package com.exp.controller;

import com.common.controller.BaseController;
import com.exp.model.UserOrder;
import com.exp.service.UserOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 Created by P0063305 on 2016/3/31.
 */
@Controller
@RequestMapping("/userOrder")
public class UserOrderController extends BaseController {
 @Autowired
 private UserOrderService userOrderService;
 /*商家订单页面*/
 @RequestMapping("/view")
 public String view() {
  return "userOrder/userOrderManageList";
 }
 /*管理员查看所有订单页面*/
 @RequestMapping("/viewAll")
 public String viewAll() {
  return "userOrder/userOrderList";
 }
 /*商家订单页面获取列表*/
 @RequestMapping("/list")
 @ResponseBody
 public List<UserOrder> list(@RequestParam Map map,HttpSession session) {
  String businessName= String.valueOf(getLoginBusiness(session).getName());
  map.put("businessName", businessName);
  List<UserOrder> orders = userOrderService.UserOrderList(map);
  return orders;
 }
 /*管理员查看所有订单页面列表*/
 @RequestMapping("/listAll")
 @ResponseBody
 public List<UserOrder> list(@RequestParam Map map) {
  List<UserOrder> orders = userOrderService.UserOrderListAll(map);
  return orders;
 }
 /*保存购买热销餐品信息*/
 @RequestMapping("/saveHot")
 @ResponseBody
 public boolean saveHot(@RequestBody UserOrder userOrder,HttpSession session){
   if(userOrder.getId()!=null){
    userOrder.setUserName(getLoginUser(session).getName());
    userOrder.setUserAddress(getLoginUser(session).getAddress());
    userOrder.setUserPhone(getLoginUser(session).getPhone());
    userOrder.setUserSex(getLoginUser(session).getSex());
    userOrder.setUserOrderTime(new Date());
    userOrderService.saveAll(userOrder);
   }
   return true;
 }
 /*保存购买热销餐品信息*/
 @RequestMapping("/saveNews")
 @ResponseBody
 public boolean saveNews(@RequestBody UserOrder userOrder,HttpSession session){
  if(userOrder.getId()!=null){
   userOrder.setUserName(getLoginUser(session).getName());
   userOrder.setUserAddress(getLoginUser(session).getAddress());
   userOrder.setUserPhone(getLoginUser(session).getPhone());
   userOrder.setUserSex(getLoginUser(session).getSex());
   userOrder.setUserOrderTime(new Date());
   userOrderService.saveAll(userOrder);
  }
  return true;
 }
 /*保存购买购买top餐品信息*/
 @RequestMapping("/saveTop")
 @ResponseBody
 public boolean saveTop(@RequestBody UserOrder userOrder,HttpSession session){
  if(userOrder.getId()!=null){
   userOrder.setUserName(getLoginUser(session).getName());
   userOrder.setUserAddress(getLoginUser(session).getAddress());
   userOrder.setUserPhone(getLoginUser(session).getPhone());
   userOrder.setUserSex(getLoginUser(session).getSex());
   userOrder.setUserOrderTime(new Date());
   userOrderService.saveAll(userOrder);
  }
  return true;
 }
}
